package club.xyes.remotedisplay.util;

import org.apache.commons.lang.time.FastDateFormat;

import java.util.Date;
import java.util.TimeZone;

/**
 * 2018/11/14 Create by 郭文梁
 * DateUtil
 * 时间日期相关工具
 *
 * @author 郭文梁
 * @date 2018/11/14
 */
public class DateUtil {
    private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("Asia/Shanghai");
    private static final FastDateFormat DATE_AND_HOURS_FORMATTER = FastDateFormat.getInstance("yyyy-MM-dd HH", TIME_ZONE);
    private static final FastDateFormat ONLY_TIME_FORMATTER = FastDateFormat.getInstance("mm:ss", TIME_ZONE);

    /**
     * 仅格式化时间
     *
     * @param date 时间
     * @return 格式化结果
     */
    public static String formatOnlyTime(Date date) {
        return ONLY_TIME_FORMATTER.format(date);
    }

    /**
     * 格式化日期个小时
     *
     * @param date 时间
     * @return 格式化结果
     */
    public static String formatDateAndHours(Date date) {
        return DATE_AND_HOURS_FORMATTER.format(date);
    }

}
